﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.IO;

namespace XmlFromOtherFormat
{
    class Program
    {
        static void Main(string[] args)
        {
            XmlDocument doc = new XmlDocument();
            XmlDeclaration declaration = doc.CreateXmlDeclaration("1.0", "UTF-8", "");
            doc.AppendChild(declaration);
            XmlElement newel = doc.CreateElement("people");
            doc.AppendChild(newel);
            StreamReader reader = new StreamReader("strange.txt");
            string line = reader.ReadLine();
            using (reader)
            {
                while (line != null)
                {
                    string[] words = line.Split(';','-');
                    string[] names = words[0].Split();
                    XmlElement person = doc.CreateElement("person");
                    newel.AppendChild(person);
                    XmlElement firstName = doc.CreateElement("firstName");
                    person.AppendChild(firstName);
                    person.AppendChild(firstName).InnerText = names[0].Trim();
                    XmlElement middleName = doc.CreateElement("middleName");
                    person.AppendChild(middleName);
                    person.AppendChild(middleName).InnerText = names[1].Trim();
                    XmlElement lastName = doc.CreateElement("lastName");
                    person.AppendChild(lastName);
                    person.AppendChild(lastName).InnerText = names[2].Trim();
                    XmlElement address = doc.CreateElement("address");
                    person.AppendChild(address);
                    person.AppendChild(address).InnerText = words[1];
                    XmlElement phone = doc.CreateElement("phone");
                    person.AppendChild(phone);
                    person.AppendChild(phone).InnerText = words[2];
                    line = reader.ReadLine();
                }
            }

            doc.Save("people.xml");
        }
    }
}
